
function postAjax(url,param,callback,errcall){
  
	jQuery.ajax(url, {
		dataType : 'json', // 服务器返回json格式数据
		type : 'post', // HTTP请求类型
		data : param,  // 传入已封装的参数
		timeout : 10000, // 超时时间设置为10秒；
		success : function(data) {
			if(callback)
				callback(data);
		},
		error : function(xhr, type, errorThrown) {			
			if(errcall)
				errcall();
			else if(callback)
				callback(errorThrown);
		}
	}); 
  
}
// 设置显示时间
function setShowtime(btn,btnhtml,wait) {
    if(wait == 0) {
        jQuery(btn).removeClass("disabled");
        jQuery(btn).html(btnhtml);       
    } else {
    	  wait--;
       jQuery(btn).addClass("disabled");
       jQuery(btn).html( "(" + wait + ")");       
       setTimeout('setShowtime("'+btn+'","'+btnhtml+'",'+wait+')', 1000);
    }

}
var Chk={
test:function(str,ps){var patt1 =new RegExp(ps); return  patt1.test(str);},
// 正则表达式验证是否为手机号码
isCHMobile:function(s){return this.test(s,/^1\d{10}jQuery/)},  
isEmail:function(s){return this.test(s,/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}jQuery/)},  
isNumber:function(s,d){return !isNaN(s.nodeType==1?s.value:s)&&(!d||!this.test(s,"^-?[0-9]*\\.[0-9]*jQuery"))},
isNoEmpty:function(s){return !jQuery.isEmptyObject(s)},
// 二段式请求:
// 请求一个地址,可以带参数,请求以后可以锁定按钮或隐藏,成功以后回调sucess1函数,异常调用error1函数
submit:function(url2,param,btn,sucess1,error1){ 
 jQuery(btn).addClass("disabled");   
	//jQuery.extend(param, {"SYSTOKENSTAMP":data} );
 postAjax(url2,param,function(result){
 	if(sucess1)
 		sucess1(result);
 	 jQuery(btn).removeClass("disabled");
 },function(result){
 			if(error1)
 				error1(result);
 			 jQuery(btn).removeClass("disabled");
 });
	},
submitByWait:function(url,param,btn,sucess2,error2){     
    	var h=jQuery(btn).html();    
    	setShowtime (btn,h,10);	
    	postAjax(url,param,sucess2,error2);
}
};


jQuery.fn.serializeObject = function(){
    var o = {};
    var a = this.serializeArray();
    jQuery.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
}


jQuery.fn.toJSON = function()      
{      
   var o = {};      
   var a = this.serializeArray();      
   jQuery.each(a, function() {  
       var name = this.name;  
       var value = this.value;  
       var paths = this.name.split(".");  
       var len = paths.length;  
       var obj = o;  
       jQuery.each(paths,function(i,e){  
           if(i == len-1){  
               if (obj[e]) {      
                   if (!obj[e].push) {      
                       obj[e] = [obj[e]];      
                   }      
                   obj[e].push(value || '');      
               } else {      
                   obj[e] = value || '';      
               }  
           }else{  
               if(!obj[e]){  
                   obj[e] = {};  
               }  
           }  
           obj = o[e];  
       });                
   });      
   return o;      
};  
jQuery.fn.toJSON2 = function()      
{      
   var o = {};      
   var a = this.serializeArray();      
   jQuery.each(a, function() {  
       var name = this.name;  
       var value = this.value;  
       var paths = this.name.split(".");  
       var key=paths[0];
       var len = paths.length;  
      
       if(len>1){
    	   if (o[key]) {                       
               o[key]+=' '+(value || '');      
           } else {      
               o[key] = value || '';      
           }  
       }else{
    	   o[key]=value|| '';    
       }              
   });      
   return o;      
};  